﻿@model AdvancedSettingsViewModel

@{
    Layout = "_LayoutAdmin";
}
@Html.AntiForgeryToken()

@section scripts{
    <script>
        $(function () {
            $(".btn-restart").click(function () {
                tryRestartWebsite();
            });

            $(".btn-reset").click(function () {
                tryResetWebsite();
            });
        });
    </script>
}

<partial name="_SettingsHeader" />

<form id="form-settings" asp-controller="Settings" asp-action="Advanced"
      data-ajax-begin="onUpdateSettingsBegin"
      data-ajax-complete="onUpdateSettingsComplete"
      data-ajax-failure="onUpdateSettingsFailed"
      data-ajax-success="onUpdateSettingsSuccess"
      data-ajax="true"
      data-ajax-method="POST">
    <div asp-validation-summary="All" class="text-danger"></div>
    <div class="row">
        <div class="col-md-6">
            <div class="card mb-4">
                <div class="card-header">@Localizer["Advanced Settings"]</div>
                <ul class="list-group list-group-flush">
                    <li class="list-group-item">
                        <label asp-for="EnablePingbackSend" class="control-label"></label>
                        <div class="material-switch float-right">
                            <input @(Model.EnablePingbackSend ? "checked=\"checked\"" : "")
                                   id="@nameof(Model.EnablePingbackSend)"
                                   name="@nameof(Model.EnablePingbackSend)" type="checkbox" value="true">
                            <label for="@nameof(Model.EnablePingbackSend)" class="label-success"></label>
                            <input name="@nameof(Model.EnablePingbackSend)" type="hidden" value="false">
                        </div>
                    </li>
                    <li class="list-group-item">
                        <label asp-for="EnablePingbackReceive" class="control-label"></label>
                        <div class="material-switch float-right">
                            <input @(Model.EnablePingbackReceive ? "checked=\"checked\"" : "")
                                   id="@nameof(Model.EnablePingbackReceive)"
                                   name="@nameof(Model.EnablePingbackReceive)" type="checkbox" value="true">
                            <label for="@nameof(Model.EnablePingbackReceive)" class="label-success"></label>
                            <input name="@nameof(Model.EnablePingbackReceive)" type="hidden" value="false">
                        </div>
                    </li>
                    <li class="list-group-item">
                        <label asp-for="EnableOpenGraph" class="control-label"></label>
                        <div class="material-switch float-right">
                            <input @(Model.EnableOpenGraph ? "checked=\"checked\"" : "")
                                   id="@nameof(Model.EnableOpenGraph)"
                                   name="@nameof(Model.EnableOpenGraph)" type="checkbox" value="true">
                            <label for="@nameof(Model.EnableOpenGraph)" class="label-success"></label>
                            <input name="@nameof(Model.EnableOpenGraph)" type="hidden" value="false">
                        </div>
                    </li>
                </ul>
                <div class="card-body">
                    <div class="form-group">
                        <label asp-for="DNSPrefetchEndpoint" class="control-label"></label>
                        <input asp-for="DNSPrefetchEndpoint" class="form-control" />
                        <span asp-validation-for="DNSPrefetchEndpoint" class="text-danger"></span>
                        <small class="form-text text-muted">@Localizer["Leave blank if you are not using a DNS service."]</small>
                    </div>
                    <div class="form-group">
                        <label asp-for="RobotsTxtContent" class="control-label"></label>
                        <textarea asp-for="RobotsTxtContent" class="form-control textarea-code" cols="60" rows="10"></textarea>
                        <span asp-validation-for="RobotsTxtContent" class="text-danger"></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    @Localizer["Options"]
                </div>
                <div class="card-body">
                    <h6>@Localizer["Clear Data Cache"]</h6>
                    <hr />
                    <div class="alert alert-warning">@Localizer["Delete cached objects both in memory and on disk"]</div>
                    <a href="javascript:;" class="btn btn-danger" data-toggle="modal" data-target="#cacheModal">@Localizer["Clear"]</a>

                    <h6 class="mt-4">@Localizer["Restart Website"]</h6>
                    <hr />

                    <div class="alert alert-warning">@Localizer["Try to shutdown and restart the website, this will terminate all current requests."]</div>

                    <a href="javascript:;" class="btn btn-danger" data-toggle="modal" data-target="#restartModal">@Localizer["Restart"]</a>

                    <h6 class="mt-4">@Localizer["System Reset"]</h6>
                    <hr />

                    <div class="alert alert-warning">@Localizer["Erase all data and configuration."]</div>

                    <a href="javascript:;" class="btn btn-danger" data-toggle="modal" data-target="#resetModal">@Localizer["Reset"]</a>
                </div>
            </div>
        </div>
    </div>
    <hr />
    <div class="form-group">
        <input id="btn-save-settings" type="submit" value="@Localizer["Save"]" class="btn btn-success" />
    </div>
</form>

<div class="modal fade" id="cacheModal" tabindex="-1" role="dialog" aria-labelledby="cacheModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="cacheModalLabel">@Localizer["Clear Data Cache"]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form id="form-clearcache" asp-controller="Settings" asp-action="ClearDataCache"
                  data-ajax-begin="onClearCacheBegin"
                  data-ajax-complete="onClearCacheComplete"
                  data-ajax-failure="onClearCacheFailed"
                  data-ajax-success="onClearCacheSuccess"
                  data-ajax="true"
                  data-ajax-method="POST">
                <div class="modal-body">
                    <ul class="list-unstyled">
                        <li>
                            <div class="custom-control custom-checkbox">
                                <input id="MCO_IMEM" value="MCO_IMEM" name="cachedObjectValues" class="custom-control-input" type="checkbox">
                                <label for="MCO_IMEM" class="custom-control-label">@Localizer["Memory Caches"]</label>
                            </div>
                        </li>
                        <li>
                            <div class="custom-control custom-checkbox">
                                <input id="MCO_OPML" value="MCO_OPML" name="cachedObjectValues" class="custom-control-input" type="checkbox">
                                <label for="MCO_OPML" class="custom-control-label">@Localizer["OPML File"]</label>
                            </div>
                        </li>
                        <li>
                            <div class="custom-control custom-checkbox">
                                <input id="MCO_FEED" value="MCO_FEED" name="cachedObjectValues" class="custom-control-input" type="checkbox">
                                <label for="MCO_FEED" class="custom-control-label">@Localizer["Subscription Feed Files"]</label>
                            </div>
                        </li>
                        <li>
                            <div class="custom-control custom-checkbox">
                                <input id="MCO_OPSH" value="MCO_OPSH" name="cachedObjectValues" class="custom-control-input" type="checkbox">
                                <label for="MCO_OPSH" class="custom-control-label">@Localizer["Open Search File"]</label>
                            </div>
                        </li>
                        <li>
                            <div class="custom-control custom-checkbox">
                                <input id="MCO_SICO" value="MCO_SICO" name="cachedObjectValues" class="custom-control-input" type="checkbox">
                                <label for="MCO_SICO" class="custom-control-label">@Localizer["Site Icon Files"]</label>
                            </div>
                        </li>
                    </ul>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-danger btn-clearcache">@Localizer["Clear"]</button>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="modal fade" id="restartModal" tabindex="-1" role="dialog" aria-labelledby="restartModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="restartModalLabel">@Localizer["Restart Website"]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                @Localizer["Are you sure to restart website? All current requests will be terminated."]
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-danger btn-restart">@Localizer["Restart"]</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="resetModal" tabindex="-1" role="dialog" aria-labelledby="resetModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="resetModalLabel">@Localizer["System Reset"]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                @Localizer["Are you ABSOLUTELY sure? ALL data and configuration will be erased!"]
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-danger btn-reset">@Localizer["Reset"]</button>
            </div>
        </div>
    </div>
</div>
